package se.plingapp.backingbeans;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import se.plingapp.enterprisebeans.MessageFacade;
import se.plingapp.entitybeans.Message;
import se.plingapp.entitybeans.User;

/**
 *
 * @author Jens Björk
 */
@ManagedBean
@RequestScoped
public class DashboardBean {

    @EJB
    private MessageFacade messageFacade;

    public List<Message> getMessages() {
        return messageFacade.findMessageFeedByUser(this.getActiveUser());
    }

    private User getActiveUser() {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (User) fc.getExternalContext().getSessionMap().get("user");
    }
}
